/*------------------------------------------------------------------------------------------------\
| Horrible X-Wing game by Steven Haber
| st_haber@hotmail.com
|
| layzar.cpp: contains a single layzar (and I do know how to spell it correctly) fired by a player
|	or enemy
\------------------------------------------------------------------------------------------------*/

#include "Layzar.h"


//Constructor takes origins, direction, sprite (color), and the render window pointer
Layzar::Layzar(float origX, float origY, bool up, sf::Sprite sprite, sf::RenderWindow *out)
{
	mUp = up;
	mSprite = sprite;
	mOut = out;
	mDistance = (float)0;
	
	//Depending on direction
	mSprite.SetLeft(origX - mSprite.GetWidth()/2);
	if(mUp)
		mSprite.SetTop(origY - mSprite.GetHeight());
	else
		mSprite.SetTop(origY);
}


//Moves the layzar and draws to buffer
bool Layzar::drawLayzar(float delta)
{
	//Conditions for direction
	if(mUp)
	{
		mSprite.Move(0, -LAYZARVELOCITY * delta);
		
		if(mSprite.GetTop() < 0 - mSprite.GetHeight())
			return false;
	}
	
	else
	{
		mSprite.Move(0, LAYZARVELOCITY * delta);
		
		if(mSprite.GetTop() > SCREENY)
			return false;
	}

	mOut->Draw(mSprite);

	return true;
}


//Returns the Y "collide point" which I defined as the middle of the layzar
float Layzar::getCollisionY()
{
	return mSprite.GetTop() + mSprite.GetHeight()/2;
}


//X collide point
float Layzar::getCollisionX()
{
	return mSprite.GetLeft() + mSprite.GetWidth()/2;
}